﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Configuration;
using System.Data.SqlClient;

/// <summary>
/// Summary description for D_Stock
/// </summary>
namespace Bestlife.ERP.DataAccess
{
public class D_Stock
{
    
	public D_Stock()
	{
		//
		// TODO: Add constructor logic here
		//
	}

    public static Boolean insert(Bestlife.ERP.Entities.E_Stock stock,string user)//insert 
    {
       
        try
        {
           
            DateTime date = System.DateTime.Now;
     
            String connStr = ConfigurationManager.ConnectionStrings["BestlifeDBConnectionString"].ConnectionString;
            Bestlife.ERP.DataAccess.Connection.connect(connStr);//connection string pass to connection class

            string proid = Bestlife.ERP.DataAccess.D_receivedstock.getproid(stock.Proid1);
            string sql = "UPDATE [Tbl_Stock] SET [Qty_in_stock] ='" + stock.Qtyinstock + "',[Last_Modify] ='" + date + "',[User_Create]='"+user+"' WHERE [Pro_Name]='" + stock.Proid1 + "'";

            Boolean add = Bestlife.ERP.DataAccess.Connection.AddEditDel(sql);
            if (add)
            {
                Connection.con.Close();
                return true;
            }
           
        }
        catch(Exception)
        {
        }
        Connection.con.Close();
        return false;
        
    }


    public static List<string> issustockchecking()
    {
        List<string> returnlist = new List<string>();
        SqlDataReader rdR;
        try
        {

            DateTime date = System.DateTime.Now;
            String connStr = ConfigurationManager.ConnectionStrings["BestlifeDBConnectionString"].ConnectionString;
            Bestlife.ERP.DataAccess.Connection.connect(connStr);//connection string pass to connection class


            String Ssql = "SELECT [Pro_Name],[Pro_ID] FROM [Tbl_Issue_Stock] where [Qty_in_stock]<=[Re_Order_Level]";

            rdR = Connection.ReadTable(Ssql);


            while (rdR.Read())
            {
                returnlist.Add(rdR["Pro_Name"].ToString());

            }

            rdR.Close();

        }
        catch (Exception)
        {

        }
        Connection.con.Close();
        return returnlist;

    }


    public static List<string> stockchecking()
    {
        List<string> returnlist = new List<string>();
        SqlDataReader rdR;
        try
        {

            DateTime date = System.DateTime.Now;
            String connStr = ConfigurationManager.ConnectionStrings["BestlifeDBConnectionString"].ConnectionString;
            Bestlife.ERP.DataAccess.Connection.connect(connStr);//connection string pass to connection class


            String Ssql = "SELECT [Pro_Name],[Pro_ID] FROM [Tbl_Stock] where [Qty_in_stock]<=[Re_Order_Level]";

            rdR = Connection.ReadTable(Ssql);


            while (rdR.Read())
            {
                returnlist.Add(rdR["Pro_Name"].ToString());

            }

            rdR.Close();

        }
        catch (Exception)
        {

        }
        Connection.con.Close();
        return returnlist;

    }
}
}